python capture exception

40

python capture exception -

# Basic syntax:
import traceback
try:
	your code here
except:
	print(traceback.format_exc())

except as Exception: -

>>> def catch():
...     try:
...         asd()
...     except Exception as e:
...         print e.message, e.args
... 
>>> catch()
global name 'asd' is not defined ("global name 'asd' is not defined",)

Comments

Submit
0 Comments